export default {
	data (){
		return {
			userInfo: {},
			expertShow: false,
			totalUnreadCount:0
		}
	},
	onShow() {
		const _this = this;
		if (!localStorage.token) {
			uni.navigateTo({
				url: '/pages/login/login'
			})
		}else{
			_this.$api.getUserInfo().then((res) => {
				_this.userInfo = res.data.result;
				localStorage.setItem('userInfo',JSON.stringify(res.data.result))
			})
		}
		setTimeout(()=>{
			const _this = this;
			_this.context = uni.createInnerAudioContext();
			_this.context.src = '/static/dingdong.mp3';
			_this.$im.Conversation.getTotalUnreadCount().then(function(totalUnreadCount) {
			  _this.totalUnreadCount = totalUnreadCount
			  if(totalUnreadCount > 0){
				  _this.context.play()
			  }
			});
			_this.$im.watch({
				message: function(event){
					_this.$im.Conversation.getTotalUnreadCount().then(function(totalUnreadCount) {
						console.log(totalUnreadCount)
					  _this.totalUnreadCount = totalUnreadCount
					});
					var message = event.message;
					if(!message.content.content){
						// 已读通知return
						return;
					}
					_this.$im.Conversation.getList({count: 30}).then(function(conversationList) {
					   const nowUser = conversationList.filter(a=>{
						   return a.targetId == message.senderUserId
					   })
					   if(nowUser[0].notificationStatus != 2){
						   return;
					   }
					   _this.context.play()
					});
				},
				status: function(event){
					var status = event.status;
				}
			})
			_this.$im.Conversation.getTotalUnreadCount().then(function(totalUnreadCount) {
			  _this.totalUnreadCount = totalUnreadCount
			});
		},800)
	},
	methods:{
		setUp() {
			uni.navigateTo({
				url:'/pages/theHead/setUp/setUp'
			})
		},
		expertClick() {
			this.expertShow = true;
		},
		notice() {
			uni.navigateTo({
				url:'/pages/index/notice'
			})
		}
	}
}